package com.jxc.action.xtpz;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.jxc.action.BaseAction;
import com.jxc.model.vo.Json;
import com.jxc.model.vo.SessionInfo;
import com.jxc.model.vo.VUser;
import com.jxc.service.UserServiceI;
import com.jxc.util.ExceptionUtil;
import com.jxc.util.ResourceUtil;
import com.opensymphony.xwork2.ModelDriven;

@Namespace("/xtpz")
@Action(value = "changePasswordAction", results = { @Result(name = "changePassword", location = "/changePassword/changePassword.jsp") })
public class ChangePasswordAction extends BaseAction implements ModelDriven<VUser> {
	private final static Logger logger = Logger.getLogger(ChangePasswordAction.class);

	@Autowired
	private UserServiceI userService;

	private VUser model = new VUser();

	@Override
	public VUser getModel() {
		return model;
	}

	public String changePassword() {
		getSubAuths("XTPZ_XGMM");
		return "changePassword";
	}

	public void edit() {
		Json j = new Json();
		try {
			SessionInfo sessionInfo = (SessionInfo) ServletActionContext.getRequest().getSession().getAttribute(ResourceUtil.getSessionInfoName());
			model.setId(sessionInfo.getUserId());
			userService.changePassword(model);
			j.setMsg("修改成功！");
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("修改失败！");
			logger.info(ExceptionUtil.getExceptionMessage(e));
		}
		super.writeJson(j);

	}

}
